import Vue from 'vue'
import Vuex from 'vuex'
import count1 from './counter1'
import count2 from './counter2'

Vue.use(Vuex)

export default new Vuex.Store({
  //定义数据
  state: {
    a:1,
    b:'b',
    arr:[1,2,3]
  },
  //获取数据
  getters: {
    total (state) {
     return  state.arr.reduce((num1, num2) => num1+num2);
    }
  
  },
  //修改数据 不适合异步函数调试发现不了
  mutations: {
    change (state,value) {
      state.a+=value;
    }
  },
  actions: {
    changeActions (context,value) {
     console.log(context);
     //调用mutations里面的change
     context.commit('change',value)

    }
  },
  modules: {
    count1,
    count2
  }
})
